package com.jd;

import java.util.concurrent.TimeUnit;

public class DeadLock {
    public static void main(String[] args) {
        new Thread(DeadLock::m1).start();
        new Thread(DeadLock::m2).start();
    }

    private static final byte[] LOCK = new byte[0];

    public static void m1() {
        synchronized (DeadLock.class) {
            System.out.println("acquire DeadLock");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (LOCK) {
                System.out.println("m1");
            }
        }
    }

    public static void m2() {
        synchronized (LOCK) {
            System.out.println("acquire LOCK");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (DeadLock.class) {
                System.out.println("m2");
            }
        }
    }
}
